<template>
  <div class="nl-card" @click.stop="clickRow('look', data)">
    <el-checkbox
      v-if="type === 'nlsq'"
      class="check-box"
      v-model="checked"
      @change="clickRow('checked', data)"
    ></el-checkbox>
    <div class="top">
      <div class="jktb" v-if="!data.jktb"></div>
      <!-- <img v-else class="jktb" :src="baseUrl + '/fpi/wjfw/download?wjbh=' + data.jktb" alt /> -->
      <div v-else class="jktb">
        <img :src="baseUrl + '/fpi/wjfw/download?wjbh=' + data.jktb" alt />
      </div>
      <div class="jkxx">
        <span :title="data.jkmc">{{ data.jkmc }}</span>
        <span :title="data.jkms">{{ data.jkms }}</span>
      </div>
      <div class="img-style" v-if="type === 'sy'">
        <!-- <img src="~@/assets/img/grzx/已申请.png" alt /> -->
        <div
          :class="data.sfksq === 'Y'&& data.syzt !== '使用中'&& data.syzt !== '申请中' ? 'img-style-align' :'img-style-aligns'"
        >
          <img
            v-if="data.sfksq === 'Y'"
            @click.stop="goPath"
            title="发起申请"
            :class="data.sfksq === 'Y'&& data.syzt !== '使用中'&& data.syzt !== '申请中' ? 'img1' :''"
            src="~@/assets/img/grzx/已申请.png"
          />
        </div>
        <!-- src="~@/assets/img/grzx/申请中.png" -->
        <!-- <img v-if="data.sfksq === 'N'" class="img1" /> -->
        <!-- <img src="~@/assets/img/grzx/已订阅.png" /> -->
        <!-- <img src="~@/assets/img/grzx /未订阅.png" alt /> -->
        <img v-if="data.syzt === '使用中'" class="img3" src="~@/assets/img/grzx/使用中.png" />
        <img v-if="data.syzt === '申请中'" class="img3" src="~@/assets/img/grzx/申请中.png" />
        <!-- <img src="~@/assets/img/grzx/已停用.png" alt /> -->
        <!-- <img src="~@/assets/img/grzx/待分类.png" alt /> -->
      </div>
      <!-- <div class="edit-style" v-if="type === 'wdfb'"></div> -->
      <div class="btn-card" v-if="type === 'wdfb'">
        <div
          :class="data.fbzt ==='已发布'|| data.fbzt ==='已停用'|| data.fbzt ==='未发布' ?'edit-card':'edit-card-updata'"
          @click.stop="clickRow('editor', data)"
        >
          <img style="width:13px;height:13px;margin-right:5px" src="~@/assets/img/grzx/修改.png" alt />
          <span>修改</span>
        </div>
        <!-- 测试判断 v-if="type === 'wdsq' && data.sfkcs === 'Y'" -->
        <div
          :class="data.fbzt ==='已发布'|| data.fbzt ==='已停用'|| data.fbzt ==='未发布' ?'edit-card':'edit-card-updata'"
          @click.stop="clickRow('test', data)"
        >
          <img style="width:17px;height:17px;margin-right:5px" src="~@/assets/img/grzx/测试.png" alt />
          <span>测试</span>
        </div>
        <div
          :class="data.fbzt ==='已发布'|| data.fbzt ==='已停用'|| data.fbzt ==='未发布' ?'edit-card':'edit-card-updata'"
          @click.stop="switchBtn()"
        >
          <el-switch
            v-model="valueData"
            @change="switchChange"
            active-value="已发布"
            :disabled="!data.jkflbh"
            :inactive-value="inactiveValue"
          ></el-switch>
          <img
            v-if="data.jkflbh && data.fbzt ==='已发布'"
            class="img3"
            src="~@/assets/img/grzx/使用中.png"
          />
          <img
            v-if="data.jkflbh && data.fbzt ==='已停用'"
            class="img3"
            src="~@/assets/img/grzx/已停用.png"
          />
          <img v-if="!data.jkflbh" class="img3" src="~@/assets/img/grzx/待分类.png" />
        </div>
        <!-- <el-button v-if="type === 'wdfb'" type="success" @click.stop="clickRow('editor', data)">修改</el-button>
        -->
      </div>

      <div v-if="type === 'wdsq'">
        <!-- v-if="data.sfkcs === 'Y' && data.jkwd" -->
        <el-button
          v-if="data.spzt === '通过'"
          type="success"
          @click.stop="clickRow('editor', data)"
        >测试</el-button>
      </div>
    </div>
    <div class="bottom" ref="bottom">
      <!-- :title="`总调用次数:${1000},今日调用次数:${10},发布时间:${
          data.fbsj
      },发布人:${data.cjrymc || data.jkfbrymc}`"-->
      <div class="item-content">
        <div class="item-content-wrap" v-if="type === 'nlsq'">
          <span>
            <img src="~@/assets/img/grzx/形状 883.png" alt />
            发布时间: {{ data.fbsj }}
          </span>
          <span>
            <img src="~@/assets/img/grzx/person.png" alt />
            发布人: {{ data.cjrymc || data.jkfbrymc }}
          </span>
          <span v-if="type === 'wdsq'" class="spzt-text">审批状态: {{ data.spzt }}</span>
          <span>
            <img src="~@/assets/img/grzx/形状 884.png" alt />
            总调用次数: {{ data.zdycs === 0 || !data.zdycs ? '-' : numRule(data.zdycs) }}
          </span>
          <span>
            <img src="~@/assets/img/grzx/形状 885.png" alt />
            今日调用次数: {{ data.jrdycs === 0 || !data.jrdycs ? '-' : data.jrdycs }}
          </span>
        </div>
        <div class="item-content-wraps" v-if="type === 'sy' || type === 'wdfb'">
          <span>
            <img src="~@/assets/img/grzx/形状 883.png" alt />
            发布时间: {{ data.fbsj }}
          </span>
          <span>
            <img src="~@/assets/img/grzx/person.png" alt />
            发布人: {{ data.cjrymc || data.jkfbrymc }}
          </span>
          <span>
            <img src="~@/assets/img/grzx/person.png" alt />&nbsp;
            <span
              :title="data.qqcgl === 0 ? '-' : data.qqcgl + '%'"
            >请求成功率: {{data.qqcgl === 0 || !data.qqcgl ? '-' : (data.qqcgl *100).toFixed(2) + '%'}}</span>
          </span>
        </div>
        <div class="item-content-wraps" v-if="type === 'sy' || type === 'wdfb'">
          <span>
            <img src="~@/assets/img/grzx/形状 884.png" alt />
            总调用次数: {{ data.zdycs === 0 || !data.zdycs ? '-' : numRule(data.zdycs) }}
          </span>
          <span>
            <img src="~@/assets/img/grzx/形状 885.png" alt />
            今日调用次数: {{ data.jrdycs === 0 || !data.jrdycs ? '-' : data.jrdycs }}
          </span>
          <span>
            <img src="~@/assets/img/grzx/形状 883.png" alt />
            平均响应时间: {{ data.qqpjhs === 0 || !data.qqpjhs ? '-' : getMs(data.qqpjhs) }}
          </span>
        </div>
        <div class="item-content-wrap-wdsq" v-if="type === 'wdsq'">
          <div>申请时间: {{ data.fbsj }}</div>
          <div>发布单位: {{ data.sqdwmc }}</div>
          <div>
            审批状态:
            <span
              :class="data.spzt === '待授权' ? 'color-skyblue' : data.spzt === '通过' ? 'color-green' : 'color-red'"
            >{{ data.spzt }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import jkglService from "@/api/jkgl";
export default {
  props: {
    data: {
      type: Object,
      default: () => { },
    },
    // wdfb：我的发布
    type: {
      type: String,
      default: "",
    },
    // 选中效果
    checked: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      baseUrl: window.BASEURL,
      // 选中效果
      // checked: false,
      valueData: this.data.fbzt,
      inactiveValue: '未发布' || '已停用'
    };
  },
  mounted() {

  },
  methods: {
    clickRow(type, data) {
      this.$emit("clickRow", type, data, this.checked);
    },
    switchBtn() {

    },
    switchChange(val) {
      if (val === '已发布') {
        const params = { jkbh: this.data.jkbh };
        jkglService
          .enableJk(params)
          .then((res) => {
            this.$message({
              type: "success",
              message: "启用成功!",
            });
            this.$emit('switchChange')
          })
          .catch((err) => {
            !err.isError &&
              this.$message({ type: "warning", message: err.message });
          });
      } else {
        this.$confirm(
          `该能力正在使用中,请确认是否停用？`,
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        ).then(() => {
          const params = { jkbh: this.data.jkbh };
          jkglService
            .updateJkdyty(params)
            .then((res) => {
              this.$message({
                type: "success",
                message: "停用成功!",
              });
              this.$emit('switchChange')
            })
            .catch((err) => {
              !err.isError &&
                this.$message({ type: "warning", message: err.message });
            });
        })
          .catch(() => {
            this.valueData = '已发布'
            this.$message({
              type: "info",
              message: "已取消",
            });
          });
      }
    },
    goPath() {
      this.$router.push({
        path: "/nlsq",
        query: {
          cs: this.data.jkbh,
        },
      }
      )
    },
    numRule(num) {
      if (num >= 1000) {
        return (num / 1000) + 'K';
      } else {
        return num;
      }
    },
    getMs(data) {
      return data / 1000 === 100 ? data + 'm' : data + 'ms'
    }
  },
};
</script>
<style lang="scss" scoped>
.nl-card {
  width: 100%;
  height: 100% !important;
  background: #fff;
  border: solid 1px #cecece;
  display: flex;
  flex-direction: column;
  padding: 0 20px;
  position: relative;
  cursor: pointer;
  &:hover {
    box-shadow: 0 2px 12px 0 rgba($color: #000000, $alpha: 0.1);
  }
  .top {
    width: 100%;
    border-bottom: 1px dashed #cecece;
    height: calc(100% - 50px);
    display: flex;
    justify-content: start;
    align-items: center;
    position: relative;
    .jktb {
      width: 55px;
      height: 55px;
      float: left;
      background: url("~@/assets/img/grzx/能力名称图标背景.png");
      display: flex;
      justify-content: center;
      align-items: center;
      img {
        width: 45px;
        height: 45px;
      }
    }
    .jkxx {
      font-size: 14px;
      color: #666;
      flex: 1;
      margin: 30px 0;
      margin-left: 10px;
      margin-right: 10px;
      span:first-child {
        color: #333333;
        font-size: 20px;
        display: inline-block;
        width: 100%;
        font-weight: bold;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        text-overflow: ellipsis;
        overflow: hidden;
      }
      span:last-child {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        text-overflow: ellipsis;
        overflow: hidden;
      }
    }
    .img-style {
      width: 120px;
      .img-style-align {
        text-align: right;
        .img1 {
          margin-top: -45px;
        }
      }

      .img-style-aligns {
        text-align: center;
        .img1 {
          margin-top: -45px;
        }
      }
      .img3 {
        position: absolute;
        top: 0;
        right: -21px;
      }
    }
  }
  .bottom {
    width: 100%;
    // height: 50px;
    .item-content {
      // float: right;
      width: 100%;
      line-height: 30px;
      padding: 10px 0;
      font-size: 12px;
      display: flex;
      flex-wrap: wrap;
      .item-content-wrap {
        display: flex;
        justify-content: flex-end;
        width: 100%;
        & > span {
          padding-left: 40px;
          // width: 50%;
          overflow: hidden;
          text-overflow: ellipsis;
          word-break: break-all;
          white-space: nowrap;
          img {
            margin-top: -2px;
          }
        }
      }

      .item-content-wraps {
        display: flex;
        width: 100%;
        & > span {
          padding-left: 10px;
          width: 50%;
          overflow: hidden;
          text-overflow: ellipsis;
          word-break: break-all;
          white-space: nowrap;
          & > span {
            width: 50%;
            overflow: hidden;
            text-overflow: ellipsis;
            word-break: break-all;
            white-space: nowrap;
          }
          img {
            margin-top: -2px;
          }
        }
      }

      .item-content-wrap-wdsq {
        display: flex;
        width: 100%;
        justify-content: space-between;
        align-content: center;
      }
    }
  }
  .btn-card {
    display: flex;
    justify-content: space-around;
    margin-top: -45px;
    // position: absolute;
    // top: 20px;
    // right: 20px;
    .edit-card {
      padding-right: 25px;
      .img3 {
        position: absolute;
        top: 0;
        right: -21px;
      }
      &:last-child {
        padding-right: 55px;
      }
    }
    .edit-card-updata {
      padding-right: 25px;
      .img3 {
        position: absolute;
        top: 0;
        right: -21px;
      }
      &:last-child {
        padding-right: 0;
      }
    }
  }
  .check-box {
    position: absolute;
    top: 5px;
    left: 7px;
    z-index: 2;
  }
  .spzt-text {
  }
}

.color-red {
  color: #f76767;
}

.color-skyblue {
  color: #0eb0ec;
}

.color-green {
  color: #38b659;
}
</style>
